package com.ikingtech.platform.service.application.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ikingtech.framework.sdk.application.model.ApplicationQueryParamDTO;
import com.ikingtech.framework.sdk.base.model.PageResult;
import com.ikingtech.framework.sdk.utils.Tools;
import com.ikingtech.platform.service.application.entity.ApplicationPageTemplateDO;
import com.ikingtech.platform.service.application.mapper.ApplicationPageTemplateMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @author tie yan
 */
@Service
@RequiredArgsConstructor
public class ApplicationPageTemplateService extends ServiceImpl<ApplicationPageTemplateMapper, ApplicationPageTemplateDO> {
    public PageResult<ApplicationPageTemplateDO> listPage(ApplicationQueryParamDTO queryParam) {
        return PageResult.build(this.page(new Page<>(queryParam.getPage(), queryParam.getRows()), Wrappers.<ApplicationPageTemplateDO>lambdaQuery()
                .like(Tools.Str.isNotBlank(queryParam.getName()), ApplicationPageTemplateDO::getTitle, queryParam.getName())
                .orderByAsc(ApplicationPageTemplateDO::getCreateTime)));
    }

    public boolean exist(String id) {
        return this.baseMapper.exists(Wrappers.<ApplicationPageTemplateDO>lambdaQuery().eq(ApplicationPageTemplateDO::getId, id));
    }
}
